package com.tjetc.config;

import com.tjetc.domain.Carousel;
import com.tjetc.domain.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;

@Configuration
public class AppConfig {
    @Bean("carouselRedisTemplate")
    public RedisTemplate<Object, Carousel> carouselRedisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<Object, Carousel> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
        Jackson2JsonRedisSerializer<Carousel> serializer = new Jackson2JsonRedisSerializer<>(Carousel.class);
        template.setDefaultSerializer(serializer);
        return template;
    }

    @Bean("typeRedisTemplate")
    public RedisTemplate<Object, Type> typeRedisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<Object, Type> template = new RedisTemplate<>();
        template.setConnectionFactory(redisConnectionFactory);
        Jackson2JsonRedisSerializer<Type> serializer = new Jackson2JsonRedisSerializer<>(Type.class);
        template.setDefaultSerializer(serializer);
        return template;
    }
}
